﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Core.Interface;
using PServiceBus.Core.Runtime.Configuration;
using PServiceBus.Core.Runtime.Transports;

namespace PServiceBus.Core.Runtime.Messages {
    [Serializable]
    public class FailedMessage : BaseMessage, IDeleteable  {
        public int RetryCount { get; set; }

        public FailedMessage() : base() {
            RetryCount = ConfigurationProvider.PublishMessageRetryCount;
        }

        public FailedMessage(TransportMessage message, Guid topicID)
            : base(message, topicID) {
            RetryCount = ConfigurationProvider.PublishMessageRetryCount;
        }

        public FailedMessage(TransportMessage message, Guid id, Guid topicID)
            : base(message, new List<MessageResponse>(), id, topicID) {
            RetryCount = ConfigurationProvider.PublishMessageRetryCount;
        }

        public bool IsValid {
            get { return !Message.IsEmpty && Responses.Count > 0 && RetryCount > 0; }
        }

        public bool IsDead {
            get { return !Message.IsEmpty && RetryCount < 1; }
        }
    }
}
